package demo15;

import java.util.Scanner;

public class demo14 {
    public static class Main{
        public static void main(String[] args){
            Scanner in=new Scanner(System.in);
            System.out.println("请输入一个字符串：");
            String s=in.next();
            TreeNode root =create(s);
            inorder(root);
        }

        public static int i=0;
        public static TreeNode create (String s){

            TreeNode root =null;
            if(s.charAt(i)!='#'){
                root=new TreeNode(s.charAt(i));
                i++;
                root.left=create(s);
                root.right=create(s);

            }else{
                i++;
            }
            return root;
        }
        public static void inorder(TreeNode root){
            if(root==null){
                return;
            }
            inorder(root.left);
            System.out.print(root.val+" ");
            inorder(root.right);
        }
    }

    //输入字符串成树
    static class TreeNode {
        public char val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode (char val){
            this.val=val;
        }
    }
}
